package ca.uvic.group2.api;

import java.util.*;
import java.io.Serializable;

public class UserInfo implements Serializable {

    public String username;
    public int userid;
    public Money balance;
    public Money reserveBalance;
    public Money triggerReserveBalance;
    public Hashtable stocks = new Hashtable();
    public List pendingBuys = new LinkedList(); // Temp, Not stored in DB
    public List pendingSells = new LinkedList(); // Temp, Not stored in DB
    public Hashtable buyTriggers = new Hashtable();
    public Hashtable sellTriggers = new Hashtable();


    public UserInfo(UserInfo src) {
        this(src.userid, src.username, src.balance, src.reserveBalance, src.triggerReserveBalance, src.stocks);
        buyTriggers.putAll(src.buyTriggers);
        sellTriggers.putAll(src.sellTriggers);
    }

    public UserInfo(int userid, String username, Money balance, Money reserveBalance, Money triggerReserveBalance, Hashtable stocks) {
        this.userid = userid;
        this.username = username;
        this.balance = balance;
        this.triggerReserveBalance = triggerReserveBalance;
        this.reserveBalance = reserveBalance;
        setStocks(stocks);
    }

    public UserInfo() {
    }

    public void setStocks(Hashtable stocks) {
        this.stocks.clear();
        if (stocks != null) {
            Iterator i = stocks.values().iterator();
            while (i.hasNext()) {
                StockRecord r = (StockRecord)i.next();
                this.stocks.put(r.stock, r);
            }
        }
    }

    public void setStocks(StockRecord[] stocks) {
        this.stocks.clear();
        if (stocks != null) {
            for (int i = 0; i < stocks.length; ++i) {
                this.stocks.put(stocks[i].stock, stocks[i]);
            }
        }
    }
}
